from .io_operation import BasicIo


# import threading
class SimpleIo:
    """
    简单的点io
    """
    IDLE = 0
    # CAMMAND_SENDED = 1
    OPERATION_CONTINUE = 2

    def __init__(self, io_param_name, channel_index=None):
        if channel_index is None:
            self.simple_io = BasicIo(io_param_name)
        else:
            self.simple_io = BasicIo("{}_{}".format(io_param_name, channel_index))
        self.current_step = self.IDLE

    def set_true(self):
        self.simple_io.set_true()
        # self.current_step = self.CAMMAND_SENDED
        self.current_step = self.LIGHTING_CONTINUE

    def set_false(self):
        if self.current_step == self.IDLE:
            return

        self.simple_io.set_false()
        self.current_step = self.IDLE

    def read_state(self):
        if self.current_step == self.IDLE:
            print("处于IDLE状态")
            return False

        return self.simple_io.read_state()
